package com.dkh.recommend.service.impl;

import com.dkh.recommend.dto.AnalysisDTO;
import com.dkh.recommend.dto.Result;
import com.dkh.recommend.entity.TbLabel;
import com.dkh.recommend.mapper.TbLabelMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dkh.recommend.service.ITbLabelService;
import com.dkh.recommend.utils.UserHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dkh
 * @since 2022-12-14
 */
@Slf4j
@Service
@Transactional
public class TbLabelServiceImpl extends ServiceImpl<TbLabelMapper, TbLabel> implements ITbLabelService {

    @Autowired
    private TbLabelMapper labelMapper;

    /**
     * 根据音乐Id获取音乐标签
     * @param musicId
     * @return
     */
    @Override
    public Result getLabelByMusicId(String musicId) {
        Long musicIdL = Long.valueOf(musicId);
        List<TbLabel> labelList = labelMapper.getMusicLabelNameBymusicId(musicIdL);
        return Result.ok(labelList);
    }

    /**
     * 喜好分析
     * @return
     */
    @Override
    public Result LikeAnalysis() {
//        当前用户id
        Long userId = UserHolder.getUser().getUserId();
        List<AnalysisDTO> analysisDTOS = labelMapper.AnalysisLike(userId);
        if (analysisDTOS.size() <= 0 || analysisDTOS.isEmpty()){
//            空 返回错误
            return Result.fail("分析错误");
        }
        return Result.ok(analysisDTOS);
    }
}
